package com.lemontree.springmvc.controller;

import com.lemontree.springmvc.model.Home;
import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.validation.Valid;

/**
 * @Author: YLBG-YCY-1325
 * @Description:
 * @Date: 2017/8/31
 */
@Controller
@RequestMapping("/index")
public class HomeController {

    @RequestMapping("/form")
    public String home() {
        Home home = new Home();
        System.out.println(home.i);
        return "form";
    }

    @RequestMapping("/error")
    public String home(@Valid Home home, Errors errors) {
        if (errors.hasErrors()) {
            System.out.println(errors.getAllErrors().get(0).getDefaultMessage());
            return "";
        }
        return "form";
    }
}
